package smartq.app;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;

import smartq.DB.BookQ;
import smartq.DB.Connect;
import smartq.DB.ServiceQ;
import smartq.general.DateTime;

import com.app.smart_q.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;


public class SmartQ_ListShowQ extends Activity {
		
	Connect con = new Connect(); 
	ResultSet rs,rs2;
	String  OID,
     		UsrOpt,
     		IsActive,
     		IsDeleted,
     		CustomerPhonenumber,
     		CustomerFirstName,
     		CustomerLastName,
     		CustomerSex,
     		CustomerClass,
     		CustomerShop,
     		CustomerFood,
     		CustomerTime,
     		CustomerAlet,
     		CustomerTable,
     		CustomerNumber,
     		CustomerStartTime,
     		CustomerEndTime,
     		CustomerQ,
     		CustomerStatus,
     		CustomerIsMessage,
     		CustomerWaittime,
     		
     		Q,
     		CustomerName,
     		Status,
     		Table,
     		StartTime,
     		EndTime,
     		WaitTime;
     
   
	
	  @SuppressWarnings("static-access")
	@Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.smartq_list);
	       
	        // listView1
	        final ListView lisView1 = (ListView)findViewById(R.id.smartq_listview2); 
	        
	        Bundle bundle = getIntent().getExtras();
			CustomerPhonenumber = (String) bundle.get("CustomerPhonenumber");
			
	        SimpleAdapter sAdap1;
	        
			ArrayList<HashMap<String, String>> MyArrList1 = new ArrayList<HashMap<String, String>>();
			HashMap<String, String> map1;
			ArrayList<HashMap<String, String>> MyArrList2 = new ArrayList<HashMap<String, String>>();
			HashMap<String, String> map2;
			
			rs = null;
			DateTime dt = new DateTime();
			String DateNow =dt.getDateNowymd();
			// TODO Auto-generated method stub
			BookQ usr = new BookQ();
			try {
				rs = usr.selectBookQ("","1",DateNow,"","");
				while(rs.next()) {
					map1 = new HashMap<String, String>();
					map1.put("OID", rs.getString("OID"));
					map1.put("Name", "คุณ "+rs.getString("CustomerFirstName"));
					map1.put("Time", rs.getString("CustomerTime"));
					map1.put("Status", rs.getString("CustomerStatus"));
					MyArrList1.add(map1);
				}
			}catch (Exception e) {
			}
			rs2 = null;
			// TODO Auto-generated method stub
			ServiceQ usr2 = new ServiceQ();
			
			try {
				rs2 = usr2.selectServiceQ("", DateNow);
				while(rs2.next()) { 
					map2 = new HashMap<String, String>();
					map2.put("Q", rs2.getString("Q"));
					map2.put("Name", "คุณ "+rs2.getString("CustomerName"));
					map2.put("Time", rs2.getString("EndTime"));
					map2.put("Status", rs2.getString("Status"));
					MyArrList2.add(map2);
				}
			}catch (Exception e) {
			}
	       
	        sAdap1 = new SimpleAdapter(SmartQ_ListShowQ.this, MyArrList1, R.layout.activity_column,
	                new String[] {"OID", "Name", "Time","Status"}, new int[] {R.id.Colum_Q, R.id.Colum_Name, R.id.Colum_Time,R.id.Colum_status}); 
	        
	        lisView1.setAdapter(sAdap1);
	  }
	
	 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
//		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	@Override
	public void onBackPressed() {
	  
		 Intent newActivity = new Intent(getApplicationContext(),SmartQ_Tap_Main.class);	                          
         newActivity.putExtra("CustomerPhonenumber", CustomerPhonenumber);
         startActivity(newActivity);
         finish();
         overridePendingTransition(R.layout.fadeendout,R.layout.fadeendin);
	    

	} 

}
